<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象的新语法</title>
</head>
<body>
<script>
  /**
   * ES 6 的 Class（类）概念
   constructor 是构造方法
   this关键字代表实例对象
   通过extends关键字实现继承
   super关键字，表示父类的构造函数，用来新建父类的this对象

   */
  //普通写法
  function Person(name, age, sex){
    this.name = name;
    this.age = age;
    this.sex = sex;

    this.say = function() {
      console.log(name);
      console.log(age);
      console.log(sex);
    }

    this.run = function() {

    }

  }

  let p = new Person("zhangsan", 10, '男');

  p.say();
  //新语法
  class Human{
    constructor(name,age,sex) {
      this.name = name;
      this.age = age;
      this.sex = sex;
    }
    say(){
      console.log(this.name);
      console.log(this.age);
      console.log(this.sex);
    }
    see(){
      console.log('看见了飞机');
    }
  }
  class Son extends Human{
    constructor(name,age,sex,other) {
      super(name,age,sex);
      this.other = other
    }
    tiao(){
      console.log('tiaogao');
    }
  }
  let s = new Son('lisi',20,'女','其它事');
  s.say();
  s.see();
  s.tiao()
  /**
   * JSON对象的新应用
   JSON.stringify()      串行化
   JSON.parse()            反串行化
   简写
   (属性和值)名字一样可以简写
   方法一样可以简写（:function省）
   */
  let one = 'saaa';
  let two = 1111;
  let newObj = {one,two,active(){
      console.log('激活');
    }};
  let str = JSON.stringify(newObj);
  console.log('str的值'+str);
  let objOther = JSON.parse(str);
  console.log('objOther的值'+objOther);
</script>
</body>
</html>